<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title></title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap-responsive.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/style.css" />
<%--<script type="text/javascript" src="js/jquery2.js"></script>--%>
<%--<script type="text/javascript" src="js/jquery2.sorted.js"></script>--%>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/bootstrap.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/ckform.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/common.js"></script>
	<script src="${pageContext.request.contextPath}/js/jquery.min.js?v=2.1.4"></script>
	<script src="${pageContext.request.contextPath}/js/commons_date.js"></script>
	
	<script>
		$(function () {
			cutData();

		});
		//首页
		function firstPage() {
			cutData(1);
		}
		//上一页
		function prePage(currentPage) {
			if (currentPage-1<1){
				cutData(1);
			}else{
				cutData(currentPage-1);
			}
		}
		//下一页
		function nextPage(currentPage,totalPage) {
			if (currentPage+1>totalPage){
				cutData(totalPage)
			}else{
				cutData(currentPage+1);
			}
		}
		//尾页
		function lastPage(totalPage) {
			cutData(totalPage);
		}
		function cutData(currentPage) {
			$.ajax({
				url:"${pageContext.request.contextPath}/blog/getAllBlogs",
				type:"get",
				data:{"currentPage":currentPage},
				dataType:"json",
				cache:false,
				success:function (rs) {
					$("#tbody").empty();
					$.each(rs.records,function (index,element) {
						var blogTr="<tr align=\"center\">\n" +
								"\t\t\t   <td>"+element.btitle+"</td>\n" +
								"\t\t\t   <td>"+element.btype.typename+"</td>\n" +
								"\t\t\t   <td>"+element.user.uname+"</td>\n" +
								"\t\t\t   <td>"+get_date(element.date)+"</td>\n" +
								"\t\t\t   <td>\n" +
								"\t\t\t\t   <a href=\"javascript:deleteBlog("+element.bid+")\">删除 </a>\n" +
								"\t\t\t\t   &nbsp;&nbsp;&nbsp;&nbsp;\n" +
								"\t\t\t\t   <a href=\"${pageContext.request.contextPath}/blog/blog_detail?bid="+element.bid+"\">博客详情</a>\n" +
								"\t\t\t   </td>\n" +
								"\t\t   </tr>";

						$("#tbody").append(blogTr);
					});
					$("#tfoot").empty();
					var cutPage="<tr>\n" +
							"\t\t\t\t<td style=\"text-align: center\" colspan=\"5\">\n" +
							"\t\t\t\t\t<a href=\"javascript:firstPage()\">首页</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n" +
							"\t\t\t\t\t<a href=\"javascript:prePage("+rs.currentPage+")\">上一页</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n" +
							"\t\t\t\t\t<a href=\"javascript:nextPage("+rs.currentPage+","+rs.totalPage+")\">下一页</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n" +
							"\t\t\t\t\t<a href=\"javascript:lastPage("+rs.totalPage+")\">尾页</a>\n" +
							"\t\t\t\t</td>\n" +
							"\t\t\t</tr>";
					$("#tfoot").append(cutPage);
				}

			})
		}

		function deleteBlog(bid) {
			$.ajax({
				url:"${pageContext.request.contextPath}/blog/deleteBlog",
				type:"post",
				data:{"bid":bid},
				dataType:"json",
				cache:false,
				success:function (rs) {
					if (rs.status==200){
						cutData();
					}else{
						alert(rs.msg);
					}
				}
			})

		}

	</script>
	
<style type="text/css">
body {font-size: 20px;
	padding-bottom: 40px;
	background-color: #e9e7ef;
}

.sidebar-nav {
	padding: 9px 0;
}

@media ( max-width : 980px) {
	/* Enable use of floated navbar text */
	.navbar-text.pull-right {
		float: none;
		padding-left: 5px;
		padding-right: 5px;
	}
}
</style>
</head>
<body>
	<form class="form-inline definewidth m20" action="#" method="get">
	<a href="${pageContext.request.contextPath}/blog/documentAdd">发布博客</a>

	</form>
	<table class="table table-bordered table-hover definewidth m10">
		<thead>
			<tr align="center">
				<th>博客标题</th>
				<th>博客类别</th>
				<th>作者</th>
				<th>发布日期</th>
				<th>管理菜单</th>
			</tr>
		</thead>
		<tbody id="tbody">
		   <%--存放行数据--%>

		</tbody>
		<tfoot id="tfoot">

		</tfoot>
	</table>

</body>
</html>
